package com.hopu.blb_erp.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.blb_erp.entity.Order2;
import com.hopu.blb_erp.entity.Order2ToBeProduced;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.mapper.Order2Mapper;
import com.hopu.blb_erp.mapper.Order2ToBeProducedMapper;
import com.hopu.blb_erp.service.Order2ToBeProducedService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class Order2ToBeProducedServiceImpl extends ServiceImpl<Order2ToBeProducedMapper, Order2ToBeProduced> implements Order2ToBeProducedService {
    @Autowired
    private Order2ToBeProducedMapper order2ToBeProducedMapper;
    @Autowired
    private Order2Mapper order2Mapper;
    @Override
    public PageEntity<Order2ToBeProduced> findAllPage(int current, int PAGE_SIZE, int orderId, int productStatus) {
        int count = Math.toIntExact(order2Mapper.selectCount(Wrappers.<Order2>lambdaQuery().eq(Order2::getProductStatus,productStatus)));
        int pageCount =  count % PAGE_SIZE==0?count/PAGE_SIZE:count/PAGE_SIZE+1;
        List<Order2ToBeProduced> order2ToBeProducedList = order2ToBeProducedMapper.selectAllLimit((current-1)*PAGE_SIZE,PAGE_SIZE,orderId,productStatus);
        PageEntity<Order2ToBeProduced> page = new PageEntity<>();
        page.setCurrent(current);
        page.setData(order2ToBeProducedList);
        page.setPageCount(pageCount);
        page.setCount(count);
        return page;
    }
}
